package com.hope;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Settings extends PreferenceFragment {
	
	public Settings() {
        // Empty constructor required for fragment subclasses
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    	View view = super.onCreateView(inflater, container, savedInstanceState);
    	
    	MainActivity.prefFragment = this;
    	
        getActivity().setTitle("Settings");
        return view;
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Load the preferences from an XML resource
        addPreferencesFromResource(R.layout.settings);
        
        Preference myPref = (Preference) findPreference("pref_tutorial");
        myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        	public boolean onPreferenceClick(Preference preference) {
        		MainActivity.visible_fragment = new Tutorial();
        		FragmentTransaction transaction = MainActivity.fragmentManager.beginTransaction();
        		getFragmentManager().beginTransaction().remove(MainActivity.prefFragment).commit();
        	
            	// Replace whatever is in the fragment_container view with this fragment,
            	// and add the transaction to the back stack which allows use of back button
            	transaction.replace(R.id.content_frame, MainActivity.visible_fragment);

            	transaction.commit();
        		return true;
            }
        });
    }
}